********************************************************************************
** Data preparation
********************************************************************************

version 15             	// Set Version number for backward compatibility
clear all               // Start with a clean slate
set more off            // Disable partitioned output
set linesize 80         // Line size limit to make output more readable
macro drop _all         // clear all macros
set matsize 800			// Change the maximum number of variables to be included

***********
*LOAD DATA*
***********

** Set path
cd ""

** Load ISSP Role of Government I-IV data
use "",clear

** Country
keep if inlist(V6, "DE-Germany":V6, "FR-France":V6, "HU-Hungary":V6,"IE-Ireland":V6,  "IT-Italy":V6, "LV-Latvia":V6, "PL-Poland":V6, "ES-Spain":V6, "SE-Sweden":V6, "GB-Great Britain":V6) 

g country=.
tostring country, replace
replace country = "Germany" if V6 ==  276
replace country = "France" if V6 ==  250
replace country = "Hungary" if V6 == 348
replace country = "Latvia" if V6 == 428
replace country = "Poland" if V6 == 616
replace country = "Spain" if V6 == 724
replace country = "Sweden" if V6 == 752
replace country = "Ireland" if V6 == 372
replace country = "UK" if V6 == 826
replace country = "Italy" if V6 == 380
encode country, gen(cntry2)

** Time
g issp=.
replace issp = 1 if V4 == 1985
replace issp = 2 if V4 == 1990
replace issp = 3 if V4 == 1996
replace issp = 4 if V4 == 2006

** Save data
save "",replace

** Load Role of Government V data
use "", clear

** Country
rename country cntry
g country=.
tostring country, replace
replace country = "Germany" if cntry ==  276
replace country = "France" if cntry ==  250
replace country = "Hungary" if cntry == 348
replace country = "Latvia" if cntry == 428
replace country = "Spain" if cntry == 724
replace country = "Sweden" if cntry == 752
replace country = "UK" if cntry == 826

** Time
g issp=.
replace issp = 5 if doi == "doi:10.4232/1.13052" 

rename AGE age
rename WRKHRS wrkhrs
rename WEIGHT weight

** Save data
save "", replace
append using "", force


*** Calculate weights ***
// total weights for whole sample
egen W = total(weight)
// total weights by country year
egen w = total(weight), by(country issp)
// new individual weights that give each country year even weights
gen wteven = weight * (W/w)
// checking weighted sample sizes
tab country issp [aw = wteven]

save "", replace




